import compile from './compile/index.js'

export const loadLibFromXre = async (runtime, source, alias) => {
  const path = source
    .map(node => node.value)
    .join('/')

  if (!runtime.modules.has(path)) {
    const X_HOME = runtime.config.get('X_HOME')
    const file = `${ X_HOME }/${ path }.x`
    runtime.modules.set(path, file)
    runtime.alias = alias
    await compile({
      runtime: runtime,
      filepath: file,
      type: 'module',
      xrehome: X_HOME
    })
  }
}
